Move Palm/OS helpers into common code so they can be used by other
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Fri, 16 Aug 2002 16:25:06 +0000 (16:25 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Fri, 16 Aug 2002 16:25:06 +0000 (16:25 +0000)
programs using Palm formats.

gpsbabel/cetus.c
gpsbabel/defs.h
gpsbabel/util.c

index ad4defe6fbd1e5930358b21c6d7b5803e29b1f9a..01d943a946850e0a6a8a4de94a3cada5d1f5e56a 100644 (file)
  */
 
 #include "defs.h"
-#if CETUS
 #include "coldsync/palm.h"
 #include "coldsync/pdb.h"
 
-typedef struct {
-       unsigned char data[4];
-} pdb_32;
-
-typedef struct {
-       unsigned char data[2];
-} pdb_16;
-
-
 struct record {
        char type;
        char ID[16]; /* Zero-terminated string. */
@@ -96,27 +86,6 @@ wr_deinit(void)
        fclose(file_out);
 }
 
-/*
- * Read 4 bytes in big-endian.   Return as "int" in native endianness.
- */
-int
-read4(pdb_32 *p)
-{
-       char *i = (char *) p;
-       return i[0] << 24 | i[1] << 16  | i[2] << 8 | i[3];
-}
-
-void
-write4(pdb_32 *pp, unsigned i)
-{
-       char *p = (char *)pp;
-
-       p[0] = (i >> 24) & 0xff;
-       p[1] = (i >> 16) & 0xff;
-       p[2] = (i >> 8) & 0xff;
-       p[3] = i & 0xff;
-}
-
 static void
 data_read(void)
 {
@@ -139,10 +108,10 @@ data_read(void)
                rec = (struct record *) pdb_rec->data;
                wpt_tmp->shortname = strdup(rec->ID);
                wpt_tmp->description = strdup(rec->name);
-               wpt_tmp->position.altitude.altitude_meters = read4(&rec->elevation) / 100.0;
+               wpt_tmp->position.altitude.altitude_meters = pdb_read4(&rec->elevation) / 100.0;
 
-               wpt_tmp->position.longitude.degrees = read4(&rec->longitude) / 10000000.0; 
-               wpt_tmp->position.latitude.degrees = read4(&rec->latitude) / 10000000.0; 
+               wpt_tmp->position.longitude.degrees = pdb_read4(&rec->longitude) / 10000000.0; 
+               wpt_tmp->position.latitude.degrees = pdb_read4(&rec->latitude) / 10000000.0; 
                if (rec->year != 0xff) {
                        struct tm tm = {0};
                        time_t tval;
@@ -194,9 +163,9 @@ cetus_writewpt(waypoint *wpt)
                rec->year = 0xff;
        }
 
-       write4(&rec->longitude, wpt->position.longitude.degrees * 10000000.0);
-       write4(&rec->latitude, wpt->position.latitude.degrees * 10000000.0);
-       write4(&rec->elevation, wpt->position.altitude.altitude_meters * 100.0);
+       pdb_write4(&rec->longitude, wpt->position.longitude.degrees * 10000000.0);
+       pdb_write4(&rec->latitude, wpt->position.latitude.degrees * 10000000.0);
+       pdb_write4(&rec->elevation, wpt->position.altitude.altitude_meters * 100.0);
 
        opdb_rec = new_Record (0, 0, ct++, sizeof(*rec), (const ubyte *)rec);
 
@@ -280,6 +249,3 @@ ff_vecs_t cetus_vecs = {
        data_read,
        data_write,
 };
-#else
-ff_vecs_t cetus_vecs;
-#endif
index 77b03cca0f7f0c3c3a19c21289f7ed472b6476ea..4b74d8d41e498e6fcff1dc8db92c7e08650bb954 100644 (file)
@@ -104,3 +104,23 @@ void fatal(const char *, ...);
 ff_vecs_t *find_vec(char *);
 
 void printposn(coord *c, int is_lat);
+
+/* 
+ * Data types for Palm/OS files.
+ */
+typedef struct {
+       unsigned char data[4];
+} pdb_32;
+
+typedef struct {
+       unsigned char data[2];
+} pdb_16;
+
+/*
+ * Protypes for Palm/OS helpers.
+ */
+
+int pdb_read2(pdb_16 *p);
+int pdb_read4(pdb_32 *p);
+void pdb_write2(pdb_16 *pp, unsigned i);
+void pdb_write4(pdb_32 *pp, unsigned i);
index 4433b4678e64385e9e325682acbed7a041b2317a..7bdf8b4d2c0353682ebf07489c3c6b49ed174f82 100644 (file)
@@ -62,3 +62,24 @@ fatal(const char *fmt, ...)
        vfprintf(stderr, fmt, ap);
        exit(1);
 }
+
+/*
+ * Read 4 bytes in big-endian.   Return as "int" in native endianness.
+ */
+int
+pdb_read4(pdb_32 *p)
+{
+       char *i = (char *) p;
+       return i[0] << 24 | i[1] << 16  | i[2] << 8 | i[3];
+}
+
+void
+pdb_write4(pdb_32 *pp, unsigned i)
+{
+       char *p = (char *)pp;
+
+       p[0] = (i >> 24) & 0xff;
+       p[1] = (i >> 16) & 0xff;
+       p[2] = (i >> 8) & 0xff;
+       p[3] = i & 0xff;
+}